<template>
  <div>
    <div>
      <el-form :inline="true" :model="form">
        <el-button-group>
          <el-button type="primary" icon="plus" @click="addHandler"/>
          <el-button type="primary" icon="edit" @click="editHandler"/>
          <el-button type="primary" icon="delete" @click="delHandler"/>
        </el-button-group>
      </el-form>
    </div>

    <el-table :data="getSyswareHouse" height="300" border :stripe="true" :highlight-current-row="true"
              @current-change="tableRowChangeClickHandler"
              style="width: 100%">
      <el-table-column prop="fundCode" label="基金代码" min-width="20%"/>
      <el-table-column prop="fundName" label="基金名称" min-width="20%"/>
      <el-table-column prop="fundType" label="基金类型" min-width="20%"/>
      <el-table-column prop="percentBefore" label="原配比(%)" min-width="20%"/>
      <el-table-column prop="percentNow" label="调仓配比(%)" min-width="20%"/>
    </el-table>


    <upload-form ref="uploadForm" :mode="formMode" :param="currentRecord"/>

    <!--<button v-clipboard="copyData" @success="copySucHandler" @error="copyErrorHandler"-->
    <!--ref="btnCopy" style="display:none">copy-->
    <!--</button>-->


  </div>
</template>

<script type="text/babel">
  import {mapActions} from 'vuex'

  import wareHouseStore from './bll/wareHouseStore'
  import store from '../../store'

  (!store.state.wareHouseStore) && store.registerModule('wareHouseStore', wareHouseStore)


  import UploadForm from './uploadForm1.vue';


  export default {
    data() {
      return {
        form: {
          region: ''
        },
        formMode: null,
        currentRecord: null
        //form: {},
      }
    },
    components: {UploadForm},
    computed: {
      getSyswareHouse() {
        return this.$store.state.wareHouseStore.wareHousefund;
      }
    },

    mounted() {
      console.log('file upload page mounted.');
      this.initPage();
    },

    methods: {
      ...mapActions(['queryTransfersfund', 'addTransfersfund', 'delTransfersfund', 'editTransfersfund']),

      initPage() {
        const warehouseId = this.$route.query.warehouseId;
        this.queryTransfersfund({warehouseId: warehouseId});
      },
      openUploadDialogHandler() {
        this.$refs.uploadDialog.open();
      },
      addHandler() {
        this.$refs.uploadForm.enable();
        this.formMode = 'ADD';
        this.$refs.uploadForm.clear();
      },
      editHandler() {
        if (!this.currentRecord) {
          this.$message.warning('请选择一条记录');
          return;
        }

        this.$refs.uploadForm.enable();
        this.formMode = 'EDIT';
      },
      delHandler() {
        if (!this.currentRecord) {
          this.$message.warning('请选择一条记录');
          return;
        }
        this.$confirm('确定删除, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          var mappingId = this.currentRecord.mappingId
          this.delTransfersfund({mappingId: mappingId}).then(() => {
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
            // this.queryBanks()
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },

      tableRowChangeClickHandler(currentRow, oldCurrentRow) {
        console.log(currentRow);
        this.currentRecord = currentRow;
        this.$refs.uploadForm.disable();
        this.formMode = 'EDIT';
      },

      addcombinationHandler() {
        if (!this.currentRecord) {
          this.$message.warning('请选择需要修改的内容');
          return;
        }
        console.log(this.currentRecord)
        this.$router.push({
          path: '/wareHouse/add',
          query: {warehouseId: this.currentRecord.warehouseId}
        })
      }
    }
  }
</script>

<style lang="scss">
  .download-url {
    padding: 5px;
  }

  .qrcode-wrapper {
    margin: auto;
  }
</style>

